package lab3_2;

public class AdditionOperation extends BinaryOperation {
    
    public AdditionOperation() {
        super();
        this.operator = '+';
    }
    
    public AdditionOperation(int left, int right) {
        super(left, right, '+');
    }
    
    @Override
    public int calculate(int left, int right) {
        return left + right;
    }
    
    @Override
    public boolean checkingCalculation(int left, int right) {
        int result = left + right;
        return result >= LOWER && result <= UPPER;
    }
    
    // 生成满足条件的加法算式
    public static AdditionOperation generateAdditionOperation() {
        int left, right;
        do {
            left = random.nextInt(UPPER + 1);
            right = random.nextInt(UPPER + 1);
        } while (!new AdditionOperation().checkingCalculation(left, right));
        
        return new AdditionOperation(left, right);
    }
}